var dzColorMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.dzcolor');
var pantoneMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.pantonecolor');
var yarnMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.yarn');
var customerMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
var fMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.factory');
var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');

var customerXmlLoader = new i18nMessage('../../servlet/BiFranceCustomerServlet?action=5');
var ctYarnMaterialXml = new i18nMessage('../../servlet/CodeTableServlet?name=CtYarnMaterial');
var ctDyeingXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtDyeing');
var ctFilsTypeXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtFilsType');
var ctColorFamilyXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtColorFamily');
var ctColorTypeXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtColorType');
var ctSeasonNumberXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtSeasonNumber');
var ctSendByXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtSendBy');
var Loader = new i18nMessage('../../servlet/CodeTableServlet?name=CtYesno');
var productDZColorStore;
var productDZColorGrid;
var productDZColorWindow;
var productDZColorUrl;

var selectProductDZColor = function(selectProductDZColorCallback, piId){
    if (!piId) {
        return;
    }
    productDZColorUrl = '../../servlet/ProductDZColorServlet?action=5&id=' + piId;
    if (!productDZColorWindow) {
        productDZColorWindow = new Ext.Window({
            title: message.get('message.combo.pleaseselect'),
            layout: 'fit',
            width: 990,
            height: 625,
            closeAction: 'hide',
            plain: true,
            modal: true,
            items: [{
                id: 'productDZColorPanel',
                region: 'center',
                bodyStyle: {
                    background: '#ffffff',
                    padding: '7px'
                },
                html: '<div id="productDZColorDiv"></div>'
            }]
        });
    }
    productDZColorWindow.show();
    
    if (productDZColorGrid) {
		productDZColorStore.proxy = new Ext.data.HttpProxy({
				url : productDZColorUrl
			});
        productDZColorStore.reload();
        return;
    }
    productDZColorStore = new Ext.data.GroupingStore({
        url: productDZColorUrl,
        
        reader: new Ext.data.XmlReader({
            record: 'item',
            id: 'id',
            totalRecords: 'itemTotal'
        }, [ 
        'sequence', 'dzColorCode', 'customerColorCode','yarnReference','yarnAccount', 'variant','photo3Name',
		'ctYarnMaterial','percentage',{
				name: 'percentage',
				type: 'float'
			},{
				name: 'loss',
				type: 'float'
			},{
				name: 'actualWeight',
				type: 'float'
			}, 'id']),
        
        groupField: 'variant',
        
        sortInfo:{
        	field: 'sequence',
        	direction: 'ASC'
        },
        
        remoteSort: false
    });
    
    var productDZColorExpander = new Ext.grid.RowExpander({
        tpl : new Ext.XTemplate(
			'<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_temp/{photo3Name}" width="150px"/></p>'
        )
    });
                
    var productDZColorSummary = new Ext.grid.GroupSummary();
				
    // create the grid
    productDZColorGrid = new Ext.grid.GridPanel({
        title: dzColorMessage.get('ui.dzcolor.listpidzcolor'),
        store: productDZColorStore,
        plugins: [productDZColorSummary, productDZColorExpander],
		stripeRows: true,
        height: 560,
        columns: [productDZColorExpander, {
            header: message.get('message.edit.sequence'),
            width: 30,
            dataIndex: 'sequence'
        },{
            header: dzColorMessage.get('ui.dzcolor.code'),
            dataIndex: 'dzColorCode'
        },{
            header: dzColorMessage.get('ui.dzcolor.customercolorcode'),
            dataIndex: 'customerColorCode'
        }
        ,{
            header: yarnMessage.get('ui.yarn.reference'),
            dataIndex: 'yarnReference'
        },{
            header: dzColorMessage.get('ui.dzcolor.variant'),
            dataIndex: 'variant'
        },{
            header: yarnMessage.get('ui.yarn.yarnaccount'),
            dataIndex: 'yarnAccount'
        },{
            header: yarnMessage.get('ui.yarn.material'),
            dataIndex: 'ctYarnMaterial'
        },{
            header: dzColorMessage.get('ui.dzcolor.percentage') + '(%)',
            align: 'right',
            dataIndex: 'percentage',
            renderer: render2D,
            summaryType:'sum'
        },{
            header: dzColorMessage.get('ui.dzcolor.loss') + '(%)',
            align: 'right',
            dataIndex: 'loss',
            renderer: render2D
        },{
            header: dzColorMessage.get('ui.dzcolor.actualweight') + '(Kg)',
            align: 'right',
            dataIndex: 'actualWeight',
            renderer: render3D,
            summaryType:'sum'
        }],
        view: new Ext.grid.GroupingView({
            forceFit: true,
			hideGroupedColumn: true,
			enableNoGroups:false,
            groupTextTpl: '&nbsp;&nbsp;<b>' + dzColorMessage.get('ui.dzcolor.variant') + ':</b>&nbsp;&nbsp;{[values.rs[0].data.variant]}'+
            '<span style="margin-left: 800px;"><a href="javascript: selectProductDZColorCallback(\'{[values.rs[0].data.id]}\', \'{[values.rs[0].data.variant]}\');productDZColorWindow.hide();"><img src="../../images/icons/arrow_rotate_clockwise.png" title="' + message.get('message.list.select') + '" /></a></span>'
        }),
        loadMask: true,
        renderTo: 'productDZColorDiv'
    });
        
    productDZColorStore.load({
        params: {
            start: 0,
            limit: 20
        }
    });
}


